package com.syezon.wifikey.news.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;


import com.syezon.wifikey.news.YiYouLiaoNewListFragment;
import com.syezon.wifikey.news.info.YiYouLiaoNewsTabBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/11/8.
 */

public class NewsTabAdapter extends FragmentStatePagerAdapter {
    private List<YiYouLiaoNewsTabBean> newsTabs = new ArrayList<YiYouLiaoNewsTabBean>();

    public void setNewsTabs(List<YiYouLiaoNewsTabBean> newsTabs) {
        this.newsTabs.clear();
        this.newsTabs.addAll(newsTabs);
        notifyDataSetChanged();
    }

    public NewsTabAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return YiYouLiaoNewListFragment.newInstance(newsTabs.get(position).getChannelTag());
    }

    @Override
    public int getCount() {
        return newsTabs.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return newsTabs.get(position)
                .getChannelName();
    }
}
